local function expireAPI_6(keys, args)
    local key = keys[1]
    local expire = args[1]
    local count = args[2]

    if redis.call('exists',key) == 0 then
       redis.call('setex',key,expire,1)
        return true
    end

    if redis.call('get',key) >= count then
       return false
    end
    redis.call('incr',key)
    return true

end
redis.register_function('expireAPI_6',expireAPI_6)


local function buy_6(keys, args)
    local key = keys[1]
    if redis.call('hget',key,'total') == '0' then
       return -1
    end
--     返回操作完的数字
    return redis.call('hincrby',key,'total',-1)


end
redis.register_function('buy_6',buy_6)